package com.agileboot.domain.medicine.db;

import com.agileboot.domain.system.user.dto.UserDTO;
import com.agileboot.domain.system.user.dto.UserRanking;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * (Medicine)表数据库访问层
 *
 * @author lx
 * @since 2023-12-02 14:20:00
 */
public interface MedicineMapper extends BaseMapper<Medicine> {
    /**
     * 根据条件分页查询角色关联的用户列表
     *
     * @param page         分页对象
     * @param queryWrapper 条件选择器
     * @return 分页处理后的草药列表
     */
    @Select("select *" +
            "from medicine" +
            " ${ew.customSqlSegment}")
    Page<Medicine> getMedicineList(Page<Medicine> page,@Param(Constants.WRAPPER)  Wrapper<Medicine> queryWrapper);

    @Select("SELECT m.creator_id userId,COUNT(m.creator_id) num,su.nickname nickname,su.sex,su.avatar,su.create_time createTime" +
            " FROM  `medicine` m " +
            " left JOIN sys_user su on  su.user_id = m.creator_id" +
            " GROUP BY m.creator_id")
    List<UserRanking> rankingUserList();
}

